<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib uri="http://www.longtop.com/intelliweb" prefix="e"%>
<%@page isELIgnored="false"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
		<title>考核体系关联指标</title>
	</head>
	<e:View id="eView" designProperty="width: 1024; height: 768">
		<script type="text/javascript"
			src="${pageContext.request.contextPath}/scripts/perform.js"></script>
		<script type="text/javascript">SkinUtil.getSkin();</script>
	    <script type="text/javascript">SkinUtil.getModuleSkin();</script>
		<div id="Invisual Controls" style="min-height: 40px; background-color: LemonChiffon;">
			<e:Dataset id="Dateset_SystemClass" pageSize="-1" datasetDefinition="DatasetDefinition_sys.dsd" datasetRef="dataset">
				<e:Field name="classId" dataType="string" label="classId" maxLength="32" />
				 <e:Field name="systemId" dataType="string" label="systemId" maxLength="32" />
				 <e:Field name="parentClassId" dataType="string" label="parentClassId" maxLength="32" />
				 <e:Field name="className" dataType="string" label="className" maxLength="100" />
				 <e:Field name="classDesc" dataType="string" label="classDesc" maxLength="200" />
				 <e:Field name="remark" dataType="string" label="remark" maxLength="400" />
			</e:Dataset>
			<e:Dataset id="Dataset_System" pageSize="10" datasetDefinition="DatasetDefinition_sys.dsd" datasetRef="dataset">
				 <e:Field name="systemId" dataType="string" label="systemId" maxLength="32" />
				 <e:Field name="systemName" dataType="string" label="systemName" maxLength="100" />
				 <e:Field name="systemDesc" dataType="string" label="systemDesc" maxLength="200" />
				 <e:Field name="objectScope" dataType="string" label="objectScope" maxLength="4" />
				 <e:Field name="remark" dataType="string" label="remark" maxLength="400" />
			</e:Dataset>
			<e:Command id="Command_Save" action="com.longtop.perform.zb.system.web.SystemClassListAction" method="hasChild" showHintInfoOnSuccess="false">
				<e:DatasetInfo name="DatasetInfo1" dataset="Dateset_SystemClass"></e:DatasetInfo>
				<e:DatasetInfo name="DatasetInfo2" dataset="Dataset_System"></e:DatasetInfo>
			</e:Command>
			<e:Command id="Command_DelData" action="com.longtop.perform.zb.system.web.SystemClassListAction" method="deleteClass" showHintInfoOnSuccess="true">
				<e:Parameter name="classId"></e:Parameter>
			</e:Command> 
			<e:ListDropDown id="LookupDropDown_objectScope" fixed="true" autoDropDown="true">
				<e:ListDropDownItem name="item1" value="10" label="机构" />
				<e:ListDropDownItem name="item2" value="01" label="个人" />
				<e:ListDropDownItem name="item3" value="11" label="机构，个人" />
			</e:ListDropDown>
			
		</div>
		<body>
			<e:Page id="ePage"
				action="com.longtop.perform.zb.system.web.SystemClassListAction"
				onAfterLoadPage="ePage_onAfterLoadPage()" onBeforeLoadPage="ePage_onBeforeLoadPage()">
				<table style="width: 100%; height: 100%;" border="0" cellpadding="2"
					cellspacing="2">
					<tr>
						<td valign="top" style="width: 20%; height: 400px;">
							<e:GroupBox
								id="GroupBoxTree" style="widh:100px;height: 390px;" title="指标体系树"
								caption="指标体系树">
								<table border="0" width="100%" height="100%" cellpadding="1"
									cellspacing="1">
									<tbody>
										<tr>
											<td><e:Button id="Button4" caption="增加指标分类"
												style="height: 20px; width: 95px" icon="/images/add.gif"
												onClick="addSort();"></e:Button></td>
											<td><e:Button id="Button5" caption="删 除"
												style="height: 20px; width: 70px" icon="/images/delete.gif"
												onClick="delData()"></e:Button> <e:Text id="systemId"
												style="width:0px" /> <e:Text id="classId" style="width:0px" />
											</td>
										</tr>
										<tr>
											<td colspan="2" valign="top">
												<e:DataTree id="dt_zbSystemClass"
													dataset="Dateset_SystemClass" nameField="classId"
													valueField="classId" parentField="parentClassId"
													labelField="className" 
													style="width: 200px; height: 353px; text-align: left"
													lazyLoading="false"
													contextMenuItems="none"
													onClickTreeNode="targetSys_onClickTreeNode(tree,node)"
													useDefaultFolderIcon="true"
													onBeforeExpandNode="dt_targetSys_onBeforeExpandNode(tree,node)"
													topParentValue="123">
												</e:DataTree>
											</td>
										</tr>
									</tbody>
								</table>
							</e:GroupBox>
						</td>
						<td style="width: 80%;" valign="top">
						<e:GroupBox id="GroupBoxDetail"
							style="width:100%; height: 415px;" title="明细信息" caption="明细信息">
							<table width="100%">
								<tr>
									<td valign="top" width="100%" height="100%">
										<table border="0" width="100%" height="100%" cellpadding="1" cellspacing="1">
											<tr>
												<td>
													<div id="classDetail" style="widh:100%;height:365px;overflow:auto;display:none">
														<iframe style="width: 99%; height: 365px" id="IframePage" name="IframePage" src="" frameborder="0"> </iframe>
													</div>
												</td>
											</tr>
										</table>
									</td>
								</tr>
							</table>
						</e:GroupBox></td>
					</tr>
				</table>
			</e:Page>
		</body>
		<script type="text/javascript">
			function ePage_onBeforeLoadPage(){
				var record = $J("Dataset_System").getCurrentRecord();
				var daset = $J("Dateset_SystemClass");
				var rootLabel=record.getValue("systemName");
				
				var rootValue=record.getValue("systemId");
				var tmp = daset.insertRecord();
				tmp.setValue("classId",rootValue);
				tmp.setValue("className",rootLabel);
				tmp.setValue("parentClassId","123");
				document.getElementById("systemId").value=record.getValue("systemId");
			}
			
			/**页面加载时，直接展开指标体系树**/
			function ePage_onAfterLoadPage(){
				
				
			
			}
			/**单击树节点，加载相应的明细页面**/
			function targetSys_onClickTreeNode(tree,node){
				$J("Button4").setEnabled(true);
				$J("Button5").setEnabled(true);
				var level = node.level;//当前节点level
				var parentId = tree.getParentNodeValue();//父节点值
				var classId = node.getValue();//当前节点值
				var url = "";
				//alert(code);
				if(level>1){
					//加载指标分类明细
					var systemId=document.getElementById("systemId").value;	
					if(classId == null){
						url = "systemClassEdit.jsp?doflag=insert&systemId=" +systemId+"parentId"+parentId ;
					}else{	
						url = "systemClassEdit.jsp?doflag=edit&classId=" + classId ;							
						 }
					onChange(url);
					document.getElementById("classDetail").style.display="";
				}else if(level == 1){
				}
				
			}
	
			/**增加指标分类**/
			function addSort(){
			var systemId = document.getElementById("systemId");
				var _tree = $J(dt_zbSystemClass);
				if (!_tree.currentNode) {
					alert("请选择相应的指标体系！");
					return;
				}
				var topCode = _tree.getCurrentNode().getValue();
				//alert(systemId.value + "---" + topCode);
				var level = _tree.getCurrentNode().level;
				if(level < 1){
					alert("请选择相应的指标体系!");
				    return;
				}
				if(systemId.value != "" && topCode != null && topCode.indexOf("未命名") == -1){
					var url = "systemClassEdit.jsp?doflag=insert&systemId=" + systemId.value + "&parentClassId=" + topCode ;
					addNode("sort",url);
				}else{
					alert("请先保存当前记录！");
				}							
			}
			/**增加树节点**/
			function addNode(flag,url){
				var tree = $J("dt_zbSystemClass");
				var node = tree.getCurrentNode();
				if(node != null){
					tree.insertChildNode();
				    onChange(url);
				}    			      	
			}
			/**删除节点**/
			function delData(){
				var _menu = $J(dt_zbSystemClass);
				//如果树对象不存在，则返回
		        if (!_menu) {
		        	alert("菜单树还未生成！");
		        	return;
		        }			
				if (!_menu.currentNode) {
					alert("请选择结点！");
					return;
				}			
				if (_menu.currentNode.isVirtualRoot) {
					alert("不能删除根结点！");
					return;
				}				
				//先从客户端树结点集对象中，判断当前结点是否有下级结点。
		        if (_menu.currentNode.childNodes && _menu.currentNode.childNodes.length > 0) {
		            alert("当前节点有下级节点，不能删除！");
		            return;
		        }	
		        var dataset = $J(Dateset_SystemClass);
				var state = dataset.currentRecord.state;
				if(state == 1 || state == 4){
					//_menu.deleteNode();
					//return;
					window.setInterval("window.location.reload()",2000);
				}
		        
		        var classId = dataset.currentRecord.getValue("classId");
				//alert("sysCode="+sysCode+"----sortCode="+sortCode);
		        if (confirm("您确定要删除菜单[" + _menu.currentNode.getLabel() + "]吗？")) {
		            //如果不是本次新增的，则去服务器上删除
		            if (state != "1" &&  state != "4") {
						Command_DelData.parameters.setValue("classId",classId);
		                var status = Command_DelData.execute();
		                if(status){	  
		                alert("操作成功");              	
		               	 window.location.reload();
		                	//_menu.deleteNode();
		                	//targetSys_onClickTreeNode(_menu,_menu.currentNode);	 
		                }
		            }
		        }
			}
			/**为panel2加载页面**/
			function onChange(url){
				var ifrm = document.getElementById("IframePage");
				if (ifrm==undefined || ifrm==null)return;
				document.getElementById("classDetail").style.display="";
				IframePage.navigate(url);
				
			}
			function dt_targetSys_onBeforeExpandNode(tree,node){
				if(node.level<=1){
					sysCode = node.getValue();
					document.getElementById("systemId").value = sysCode;
				}
			}	
		</script>
	</e:View>
</html>
